home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Code Resources
/
Windows 95 MDEF
/
Sourcery
/
DrawMenuItem.cpp
next >
Wrap
C/C++ Source or Header
|
1996-06-12
|
8KB
|
289 lines
#include "DrawMenuItem.h"
#include "Win95Look.h"
void DrawItemSeparator(Rect *itemRect, MDEFstuff *mdefData);
void DrawItemMark(
char theMark,
short hiliteState,
Rect *itemRect,
MDEFstuff *mdefData);
void DrawMenuItemText(
Str255 itemText,
short hiliteState,
short itemMarkOffset,
Rect *itemRect,
MenuHandle whichMenu,
short menuItem,
MDEFstuff *mdefData);
void DrawSubMenuTriangle(
Rect *itemRect,
short hiliteState,
MDEFstuff *mdefData);
void DrawCmdKey(
char theChar,
short hiliteState,
Rect *itemRect,
MDEFstuff *mdefData);
// ---------------------------------------------------------------------------
// DrawMenuItem.
// The "meat" of this MDEF. Does the actual drawing.
// Draws the menu item's frame, item text, cmd-keys, and submenu symbols.
// It does this and also accounts for menu item's enabled/disabled status,
// among other things. Pretty tedious.
void DrawMenuItem(MenuHandle whichMenu, Rect *menuRect, short whichItem,
short hiliteState, MDEFstuff *mdefData) {
Str255 itemText;
Rect itemRect;
Boolean itemDisabled;
short itemMarkOffset = 0;
// Get text of menu item.
GetItem(whichMenu, whichItem, itemText);
// Determine menu item's rect.
GetMenuItemRect(menuRect, &itemRect, whichItem);
// Do some rect clipping & fudging
InsetRect(&itemRect, kRectPadding, kRectPadding);
// Catch special menu item cases, such as the dividing line "(-"
if (itemText[1] == kDividerChar) {
DrawItemSeparator(&itemRect, mdefData);
return; // No more to draw, so exit
}
itemDisabled = IsItemDisabled(whichMenu, whichItem);
if (hiliteState == kMenuUnhilited) {
RGBForeColor(&(mdefData->params).menuBkgndColor);
PaintRect(&itemRect);
}
else {
RGBForeColor(&(mdefData->params).menuSelectionColor);
PaintRect(&itemRect);
}
if (itemDisabled)
hiliteState = kMenuDisabled;
// Draw item mark, if any. Remember to note if menu item is disabled or not
itemMarkOffset = CharWidth(kCheckMarkChar) + kItemMarkPadding;
short theMark, theChar;
GetItemMark(whichMenu, whichItem, &theMark);
GetItemCmd(whichMenu, whichItem, &theChar);
if (theMark != noMark && theChar != hMenuCmd) {
// Not a submenu, but an actual item mark, so we have to draw it
DrawItemMark(theMark, hiliteState, &itemRect, mdefData);
}
// Now time to draw the menu item text itself...
DrawMenuItemText(itemText, hiliteState, itemMarkOffset,
&itemRect, whichMenu, whichItem, mdefData);
// Alright, time to draw Cmd-keys and/or submenu triangles
switch(theChar) {
case kSubmenuCode:
DrawSubMenuTriangle(&itemRect, hiliteState, mdefData);
break;
case kScriptCode:
case kUseICONCode:
case kUseSICNCode:
// Not supported in this version. Do nothing.
break;
default:
if (theChar != 0)
DrawCmdKey(theChar, hiliteState, &itemRect, mdefData);
break;
}
} // END DrawMenuItem
// ---------------------------------------------------------------------------
void DrawItemSeparator(Rect *itemRect, MDEFstuff *mdefData) {
// Find height of menu item, divided by two
short halfWay = (itemRect->bottom - itemRect->top) / 2;
MoveTo(itemRect->left + 1, itemRect->top + halfWay);
W95LineTo(itemRect->right - 1, itemRect->top + halfWay,
&(mdefData->params).menuShadowColor,
&(mdefData->params).menuHiliteColor);
} // END DrawItemSeparator
// ---------------------------------------------------------------------------
/*
Always use system font for drawing item marks, so checkmarks, bullets,
etc. will always be available no matter what font the user is using
for the menu text...
*/
void DrawItemMark(
char theMark,
short hiliteState,
Rect *itemRect,
MDEFstuff *mdefData) {
short textLocH, textLocV;
RGBColor *textColor;
textLocH = itemRect->left + kWidthPadding;
textLocV = itemRect->bottom - kHeightPadding + kTextHtPadding;
TextFont(systemFont);
MoveTo(textLocH, textLocV);
if (hiliteState != kMenuDisabled)
textColor = &(mdefData->black);
else
textColor = &(mdefData->params).menuShadowColor;
W95DrawChar(theMark, textColor, &(mdefData->params).menuHiliteColor);
TextFont((mdefData->params).menuFont);
} // END DrawItemMark
// ---------------------------------------------------------------------------
/*
The menuFace parameter in the 'MnuT' resource defines the textFace for
the entire menu. If however, an individual menu item has a text style
other than plain, it will override the settings in the 'MnuT' resource
for that menu.
*/
void DrawMenuItemText(
Str255 itemText,
short hiliteState,
short itemMarkOffset,
Rect *itemRect,
MenuHandle whichMenu,
short menuItem,
MDEFstuff *mdefData) {
short textLocH, textLocV;
Style textStyle;
RGBColor *textColor;
GetItemStyle(whichMenu, menuItem, &textStyle);
if (textStyle) {
TextFace(textStyle);
}
/*
Determine which colors to draw the text in, based on whether
the text is disabled, and whether we adhere strictly to
the Windows95 look.
*/
if (hiliteState == kMenuDisabled) {
textColor = &(mdefData->params).menuShadowColor;
}
else {
if ((mdefData->params).exactWin95Look) {
if (hiliteState == kMenuHilited)
textColor = &mdefData->white;
else
textColor = &mdefData->black;
}
else
textColor = &mdefData->black;
}
textLocH = itemRect->left + kWidthPadding - 1 + itemMarkOffset;
textLocV = itemRect->bottom - kHeightPadding + kTextHtPadding;
/*
If the item is disabled, or if we're not using the "exact"
Windows95 look, we draw the text embossed. Else we draw
the text plainly.
*/
if (hiliteState == kMenuDisabled || !(mdefData->params).exactWin95Look) {
W95DrawTextAt((Ptr)&itemText[1], itemText[0],
textLocH, textLocV, textColor, &(mdefData->params).menuHiliteColor);
}
else {
RGBForeColor(textColor);
MoveTo(textLocH, textLocV);
DrawString(itemText);
}
TextFace((mdefData->params).menuFace);
} // END DrawMenuItemText
// ---------------------------------------------------------------------------
void DrawSubMenuTriangle(
Rect *itemRect,
short hiliteState,
MDEFstuff *mdefData) {
// Draw submenu symbol
Rect subMenuRect;
RGBColor *lineColor;
RGBColor *hiliteColor;
RGBColor fillColor;
SetRect(&subMenuRect, 0, 0, kSubMenuWd, kSubMenuHt);
subMenuRect.top = (itemRect->top +
((itemRect->bottom - itemRect->top) / 2)) - (kSubMenuHt / 2);
subMenuRect.right = itemRect->right - kRectPadding - 4;
subMenuRect.left = subMenuRect.right - kSubMenuWd;
subMenuRect.bottom = subMenuRect.top + kSubMenuHt;
if ((mdefData->params).exactWin95Look) {
if (hiliteState == kMenuHilited) {
fillColor.red = fillColor.green = fillColor.blue = 0xFFFF;
}
else if (hiliteState == kMenuUnhilited) {
fillColor.red = fillColor.green = fillColor.blue = 0x0000;
}
else {
// Disabled.
fillColor = (mdefData->params).menuShadowColor;
}
lineColor = hiliteColor = &fillColor;
}
else {
lineColor = &(mdefData->black);
hiliteColor = &(mdefData->params).menuHiliteColor;
}
W95DrawTriangleRight(&subMenuRect, (mdefData->params).exactWin95Look,
lineColor, hiliteColor, &fillColor);
} // END DrawSubMenuTriangle
// ---------------------------------------------------------------------------
void DrawCmdKey(
char theChar,
short hiliteState,
Rect *itemRect,
MDEFstuff *mdefData) {
short textLocH, textLocV;
short cmdWidth;
RGBColor *textColor;
cmdWidth = CharWidth(kWidestChar); // "W" is widest character (I think)
cmdWidth += CharWidth(kCmdKeyChar); // "Cmd" key character
textLocH = itemRect->right - (kCmdKeyPadding + cmdWidth);
textLocV = itemRect->bottom - kHeightPadding + kTextHtPadding;
if (hiliteState != kMenuDisabled)
textColor = &mdefData->black;
else
textColor = &(mdefData->params).menuShadowColor;
TextFont(systemFont);
TextFace(0);
MoveTo(textLocH, textLocV);
W95DrawChar(kCmdKeyChar, textColor, &(mdefData->params).menuHiliteColor);
TextFont((mdefData->params).menuFont);
TextFace((mdefData->params).menuFace);
W95DrawChar(theChar, textColor, &(mdefData->params).menuHiliteColor);
} // END DrawCmdKey